<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_address".
 *
 * @property string $id
 * @property string $user_id
 * @property string $name
 * @property string $phone
 * @property string $province_name
 * @property string $city_name
 * @property string $region_name
 * @property string $address
 * @property string $postcode
 * @property integer $is_default
 * @property integer $is_enabled
 * @property string $remark
 * @property string $mini_program_id
 *
 * @property TUser $user
 */
class Address extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_address';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['is_default', 'is_enabled'], 'integer'],
            [['id', 'user_id', 'mini_program_id'], 'string', 'max' => 36],
            [['name', 'province_name', 'city_name', 'region_name', 'address', 'postcode', 'remark'], 'string', 'max' => 255],
            [['phone'], 'string', 'max' => 20],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => TUser::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'name' => 'Name',
            'phone' => 'Phone',
            'province_name' => 'Province Name',
            'city_name' => 'City Name',
            'region_name' => 'Region Name',
            'address' => 'Address',
            'postcode' => 'Postcode',
            'is_default' => 'Is Default',
            'is_enabled' => 'Is Enabled',
            'remark' => 'Remark',
            'mini_program_id' => 'Mini Program ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(TUser::className(), ['id' => 'user_id']);
    }
}
